package com.example.onlinemarket.model;

import java.util.Arrays;
import java.util.Objects;

import static com.example.onlinemarket.Application.download;
import static com.example.onlinemarket.util.FileUtil.externalFilesDir;
public class Good {
    private Integer goodId;//商品ID
    private String goodName;//商品名
    private Integer quantity;//商品库存
    private Integer sellNum;//商品销量
    private Double sellPrice;//商品售价
    private Double purchasePrice;//商品进价
    private Integer userId;//商家ID
    private String description;//商品描述
    private String species;//商品种类
    private boolean status;//商品状态(上架/下架)
    private String imgPath;//服务器上商品图片文件获取地址
    private String localPath;//本地商品图片文件存放位置
    private byte[] photo;//鲜花图片

    @Override
    public boolean equals(Object o) {
        if (this == o) return true;
        if (!(o instanceof Good)) return false;
        Good good = (Good) o;
        return isStatus() == good.isStatus() &&
                Objects.equals(getGoodId(), good.getGoodId()) &&
                Objects.equals(getGoodName(), good.getGoodName()) &&
                Objects.equals(getQuantity(), good.getQuantity()) &&
                Objects.equals(getSellNum(), good.getSellNum()) &&
                Objects.equals(getSellPrice(), good.getSellPrice()) &&
                Objects.equals(getPurchasePrice(), good.getPurchasePrice()) &&
                Objects.equals(getUserId(), good.getUserId()) &&
                Objects.equals(getDescription(), good.getDescription()) &&
                Objects.equals(getSpecies(), good.getSpecies()) &&
                Objects.equals(getImgPath(), good.getImgPath());
    }

    @Override
    public int hashCode() {
        return Objects.hash(getGoodId(), getGoodName(), getQuantity(), getSellNum(), getSellPrice(), getPurchasePrice(), getUserId(), getDescription(), getSpecies(), isStatus(), getImgPath(), getLocalPath());
    }

    //从服务器获取商品照片
    public void getGoodImg(){
        download(imgPath);
        localPath = externalFilesDir+imgPath;
    }

//    @Override
//    public String toString() {
//        return "Good{" +
//                "goodId=" + goodId +
//                ", goodName='" + goodName + '\'' +
//                ", quantity=" + quantity +
//                ", sellNum=" + sellNum +
//                ", sellPrice=" + sellPrice +
//                ", purchasePrice=" + purchasePrice +
//                ", userId=" + userId +
//                ", description='" + description + '\'' +
//                ", species='" + species + '\'' +
//                ", status=" + status +
//                '}';
//    }


    @Override
    public String toString() {
        return "Good{" +
                "goodId=" + goodId +
                ", goodName='" + goodName + '\'' +
                ", quantity=" + quantity +
                ", sellNum=" + sellNum +
                ", sellPrice=" + sellPrice +
                ", purchasePrice=" + purchasePrice +
                ", userId=" + userId +
                ", description='" + description + '\'' +
                ", species='" + species + '\'' +
                ", status=" + status +
                ", imgPath='" + imgPath + '\'' +
                ", localPath='" + localPath + '\'' +
                ", photo=" + Arrays.toString(photo) +
                '}';
    }

    public Integer getGoodId() {
        return goodId;
    }

    public void setGoodId(Integer goodId) {
        this.goodId = goodId;
    }

    public String getGoodName() {
        return goodName;
    }

    public void setGoodName(String goodName) {
        this.goodName = goodName;
    }

    public Integer getQuantity() {
        return quantity;
    }

    public void setQuantity(Integer quantity) {
        this.quantity = quantity;
    }

    public Integer getSellNum() {
        return sellNum;
    }

    public void setSellNum(Integer sellNum) {
        this.sellNum = sellNum;
    }

    public Double getSellPrice() {
        return sellPrice;
    }

    public void setSellPrice(Double sellPrice) {
        this.sellPrice = sellPrice;
    }

    public Double getPurchasePrice() {
        return purchasePrice;
    }

    public void setPurchasePrice(Double purchasePrice) {
        this.purchasePrice = purchasePrice;
    }

    public Integer getUserId() {
        return userId;
    }


    public byte[] getPhoto() {
        return photo;
    }

    public void setPhoto(byte[] photo) {
        this.photo = photo;
    }

    public void setUserId(Integer userId) {
        this.userId = userId;
    }

    public String getDescription() {
        return description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    public String getSpecies() {
        return species;
    }

    public void setSpecies(String species) {
        this.species = species;
    }

    public boolean isStatus() {
        return status;
    }

    public void setStatus(boolean status) {
        this.status = status;
    }

    public String getImgPath() {
        return imgPath;
    }

    public void setImgPath(String imgPath) {
        this.imgPath = imgPath;
    }

    public String getLocalPath() {
        return localPath;
    }

    public void setLocalPath(String localPath) {
        this.localPath = localPath;
    }
}
